//获取应用实例
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    request_common_para: app.globalData.request_common_para,
    custFinishList: {
      list: []
    },
    isShowMenu: false,
    curMenu: '成功战败',
    menuList: null,
    pageNo: 0,
    maxPage: 0,
    queryParam: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      menuList: app.globalData.menuListData,
      request_common_para: app.globalData.request_common_para,
      pageNo: 0
    })

    var data = this.data.request_common_para;

    data.pageNo = 0
    data.pageBusiCode="30"
    var that = this
    wx.request({
      url: app.getHost() + "/datalake/v1/userManages/getMatchUserManages",
      data: data,
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.info(JSON.stringify(res.data.list))
        if (res.statusCode == 200) {
          that.setData({
            custFinishList: { list: res.data.list },
            pageNo: 0,
            maxPage: res.data.maxPage,
            queryParam: ''
          })
        }
      },
      complete: function (res) {
      }
    });
  },

  searchBox: function (e) {
    var that = this;
    var data = this.data.request_common_para
    data.pageBusiCode = "30"
    data.pageNo = 0
    data.carModel = e.detail.value
    wx.request({
      url: app.getHost() + "/datalake/v1/userManages/getMatchUserManages",
      data: data,
      method: "POST",
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        if (res.statusCode == 200) {
          that.setData({
            custFinishList: { list: res.data.list },
            pageNo: 0,
            maxPage: res.data.maxPage,
            queryParam: e.detail.value
          })
        }
      },
      complete: function (res) {
      },
      fail: function (res) {
        console.error(res);
      }
    });
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    app.toast3Tap();
    this.onLoad();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    let maxPage = this.data.maxPage;
    let pageNo = this.data.pageNo;
    if (maxPage > pageNo) {
      pageNo++;
      this.setData({
        pageNo: pageNo

      })
      app.toast3Tap()
      var that = this;
      var data = this.data.request_common_para
      data.pageBusiCode = "30"
      data.pageNo = pageNo
      if (this.data.queryParam) {
        data.carModel = this.data.queryParam
      }
      wx.request({
        url: app.getHost() + "/datalake/v1/userManages/getMatchUserManages",
        data: data,
        method: "POST",
        header: {
          'content-type': 'application/json' // 默认值
        },
        success: function (res) {
          if (res.statusCode == 200) {
            let custFinishList = that.data.custFinishList.list;
            for (let i in res.data.list) {
              custFinishList.push(res.data.list[i])
            }
            that.setData({
              custFinishList: { list: custFinishList },
              pageNo: pageNo,
              maxPage: res.data.maxPage
            })
          }
        },
        complete: function (res) {
        },
        fail: function (res) {
          console.error(res);
        }
      });


    }

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  toggleMenuList: function (e) {
    let { isShowMenu } = this.data;

    this.setData({
      isShowMenu: !isShowMenu
    })
  },
  navigatorPage: function (e) {
    let dataset = e.currentTarget.dataset;
    let pages = getCurrentPages();
    let currPage = pages[pages.length - 1];

    if ('/' + currPage.route == dataset.url) {
      return
    }

    this.setData({
      isShowMenu: false
    })
    wx.reLaunch({
      url: dataset.url
    })
  }
})